<?php
class ControllerModuleSocialLogin extends AdminController {

	public function index() {

		$this->document->setTitle($this->_['module_name']);

		M('setting/setting');

		if ($this->request->isPost() && $this->validate()) {
			$this->model_setting_setting->editSetting('social_login', $this->request->post);

			$this->session->set_flashdata('success', $this->_['text_success']);
			$this->redirect(UA('extension/module'));
		}

  		$this->data['breadcrumbs'] = array();

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->_['text_home'],
			'href'      => UA('common/home'),
      		'separator' => false
   		);

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->_['text_module'],
			'href'      => UA('extension/module'),
      		'separator' => ' :: '
   		);

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->_['module_name'],
			'href'      => UA('module/social_login'),
      		'separator' => ' :: '
   		);

		if (isset($this->request->post['social_login_module'])) {
			$this->data['modules'] = $this->request->post['social_login_module'];
		} elseif (C('social_login_module')) {
			$this->data['modules'] = C('social_login_module');
		}
		else {
			$this->data['modules'] = array(
				array(
					'window_mode' => 'dialog',
					'layout_id' => 0,
					'position'  => '',
					'status' => 1,
					'sort_order' => 0,
					'Facebook_client_id' => '',
					'Facebook_client_secret' => '',
					'Facebook_oauth_status' => 0,
					'Google_client_id' => '',
					'Google_client_secret' => '',
					'Google_oauth_status' => 0
				)
			);
		}
		
		M('design/layout');
		$this->data['layouts'] = $this->model_design_layout->getLayouts();
		
		$this->display('module/social_login.tpl');
	}

	protected function validate() {
		if (!$this->hasMP()) {
			$this->setMessage('error_warning', $this->_['error_permission']);
			return false;
		}

		return true;
	}
}
?>